<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>已退货的货品</title>
    <link type="text/css" rel="stylesheet" href="./layui/css/layui.css"/>
    <style rel="stylesheet" type="text/css">
        .right{
            margin-right: 5px;
            text-align: center;
        }
    </style>
</head>

<body class="layui-layout-body">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>已退货的货品</legend>
</fieldset>

<table id="product" lay-filter="test"></table>
<script type="text/html" id="toolBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="buy">重新购入</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="buyandsale">重新购入并上架</a>
</script>
<script src="./layui/layui.all.js"></script>
<script>
    var $ = layui.jquery;
    var table = layui.table;
    var element = layui.element;
        table.render({
            elem: '#product'
            , height: 500
            , url: '/selectreturnproduct.action' //数据接口
            , cols: [[ //表头
                {field: 'pid', title: 'ID', width: 80, sort: false, fixed: 'left'}
                , {field: 'pname', title: '货品名称', width: 190}
                , {field: 'pgetprice', title: '货品进价', width: 150, sort: false}
                , {field: 'psaleprice', title: '货品售价', width: 200, sort: false}
                , {field: 'pduetime', title: '过期时间', width: 240, sort: false}
                , {field: 'pcount', title: '货品数量', width: 120, sort: false}
                , {width: 300, title: '常用操作', align: 'center', toolbar: '#toolBar', fixed: 'right'}

            ]]
            ,page : true
        });
</script>
<script>
    //监听工具条
    table.on('tool(test)', function (obj) {
        if (obj.event === 'buy') {
            var data = obj.data;
            layer.confirm('确认重购该商品吗?', function (index) {
                $.ajax({
                    "url": "/buy.action?pid=" + data.pid,
                });
                obj.del();
                layer.close(index);
            });
        } else if (obj.event === 'buyandsale') {
            var data = obj.data;
            layer.confirm('确认重购该商品并上架吗?', function (index) {
                $.ajax({
                    "url": "/buyandsale.action",
                    type: "POST",
                    data: data
                });
                obj.del();
                layer.close(index);
            });
        }
    });
</script>
</body>
</html>